Does earthquake always happen at night?
logo

Loading data


The earthquake data is from USGS.gov. Variables in the dataset and their meanings:

  • time: Time when the event occurred. Times are reported in milliseconds since the epoch ( 1970-01-01T00:00:00.000Z), and do not include leap seconds. In certain output formats, the date is formatted for readability.
  • latitude: Decimal degrees latitude. Negative values for southern latitudes.
  • longitude: Decimal degrees longitude. Negative values for western longitudes.
  • depth: Depth of the event in kilometers.
  • mag: The magnitude for the event.
  • magType: The method or algorithm used to calculate the preferred magnitude for the event.
  • place: Textual description of named geographic region near to the event.

Show data


library(DT)
datatable(
  data, 
  rownames = FALSE, 
  filter = "top", 
  options = list(pageLength = 10, scrollX = T)
)

Earthquake happen time


p1 <- temp %>% 
  mutate(date = lubridate::floor_date(timestamp, 'weeks'), 
         is_day = if_else(is_day, '日间', '夜间')) %>% 
  count(date, is_day) %>% 
  ggplot(aes(date, n)) + 
  geom_line(aes(color = is_day)) + 
  geom_smooth(aes(color = is_day), se = FALSE) + 
  scale_color_manual(values = c('日间' = '#ffb84d', '夜间' = '#3a6589')) + 
  labs(x = NULL, y = 'count weekly', title = 'earthquake count on if happened at night', 
       color = NULL, 
       subtitle = 'mag level >= 2.5\nruns test p value: 0.7009211', 
       caption = 'dataSource: USGS.gov') + 
  theme_minimal() + 
  theme(legend.position = 'bottom')

p2 <- temp %>% 
  filter(mag >= 4.5) %>% 
  mutate(date = lubridate::floor_date(timestamp, 'weeks'), 
         is_day = if_else(is_day, '日间', '夜间')) %>% 
  count(date, is_day) %>% 
  ggplot(aes(date, n)) + 
  geom_line(aes(color = is_day)) + 
  geom_smooth(aes(color = is_day), se = FALSE) + 
  scale_color_manual(values = c('日间' = '#ffb84d', '夜间' = '#3a6589')) + 
  labs(x = NULL, y = 'count weekly', title = 'earthquake count on if happened at night', 
       color = NULL, 
       subtitle = 'mag level >= 4.5\nruns test p value: 0.6062803', 
       caption = 'dataSource: USGS.gov') + 
  theme_minimal() + 
  theme(legend.position = 'bottom')

cowplot::plot_grid(p1, p2)

Wald–Wolfowitz runs test


runs_test <- function(x) {

  R <- length(rle(x)$length) # observed runs
  n_1 <- length(x[x == 0])
  n_2 <- length(x[x == 1])
  R_ <- (2 * n_1 * n_2) / (n_1 + n_2) + 1 # expected runs
  s_R <- (2 * n_1 * n_2 * (2 * n_1 * n_2 - n_1 - n_2)) / ( (n_1 + n_2)^2 *   (n_1 + n_2 - 1) )
  
  Z <- (R - R_) / s_R # test statitics
  
  # H0:  the sequence was produced in a random manner
  # Ha:  the sequence was not produced in a random manner  
  
  p.value <- 2 * pnorm(-abs(Z))
  p.value
}
 




A work by ashther